@import "_variables";

/**
 * reset global
 */
html, body {
    margin: 0;
    font-size: $font-size-main;
    position: relative;

    a {
        outline: none;
    }
}

/**
 * responsive breaks
 */
$break-level-1: 320px;
$break-level-2: 414px;
$break-level-3-1: 680px;
$break-level-3: 768px;
$break-level-4: 900px; // > 900px timeline will work.
$break-level-5: 980px;

/* 980px work fine */

/**
 * Global settings of layout
 */

.container {
    box-sizing: border-box;
    margin: auto;
    width: 100%;
    max-width: 720px;

    @media only screen and (max-width: $break-level-5) {
        max-width: 680px;
    }

    @media only screen and (max-width: $break-level-3) {
        max-width: 88.54%;
    }

    @media only screen and (max-width: $break-level-2) {
        max-width: 95%;
    }
}


body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    color: #333;
    font-family: $font-content;
}

article {
    flex-grow: 1;
}

/**
 * header
 */
header {
    padding: 1em 0;

    background: #333;
    color: #F1F1F1;

    .container{
        font-family: $font-blog-title;
        border-bottom: .3em solid #333;

        .title {
            color: #EEE;
            text-decoration: none;
            font-size: 2.4em;
        }
        .subtitle {
            color: #aaa;
            font-size: 1.4em;
            margin-left: 1.2em;
        }
    }
    @media only screen and (max-width: $break-level-2) {
        padding: 0;

        .container.header {
            display: flex;
            align-items: center;

            .title {
                flex: 1;
            }
            .subtitle {
                display: none;
            }
        }
    }
}

/* navigation bar */
nav {
    top: 0;
    position: sticky;
    background: #333;
    font-family: $font-mono;
    font-size: 1em;
    z-index: 10;

    @media only screen and (max-width: $break-level-2) {
        position: static;
    }
}

#nav {
    text-align: right;

    a {
        &, &:visited {
            text-decoration: none;
            color: #F1F1F1;
        }

        padding: .625em 1.25em;
        display: inline-block;
        position: relative;

        // decoration
        &::after {
            content: '';
            display: block;
            position: absolute;
            right: -3px;
            top: 19px;
            height: 6px;
            width: 6px;
            background: white;
            opacity: 0.5;
        }

        // for hover style
        &::before {
            content: '';
            display: block;
            position: absolute;
            left: 0;
            bottom: 0;
            height: 3px;
            width: 0;
            background: $color-underscore;
            transition: width .25s;
        }

        &.active, &:hover {
            &::before {
                width: 100%;
            }
        }

        &:last-child::after {
            display: none;
        }
    }
}

/* menu button on small screen */
#menu {
    position: absolute;
    top: -9999px;
    left: -9999px;
}

#toggle-menu{
    cursor: pointer;
    user-select: none;
    display: none; // large display, hide it
}

@media only screen and (max-width: $break-level-2) {
    #toggle-menu {
        display: block;
        color: #EEE;
        font-size: 2.2em;
    }

    #nav {
        display: none;
    }

    #menu:checked ~ #nav {
        display: block;

        a {
            display: block;

            // style
            color: #CCC;
            border-bottom: 1px solid #CCC;

            &:last-child {
                border-bottom: none;
            }

            &:hover {
                background: #CCC;
                color: #333;
            }

            // disable hover style
            &::before {
                display: none;
            }

            // enable decoration
            &:last-child::after {
                display: block;
            }
        }
    }
}

#header-margin-bar {
    margin: 20px 0;
}

/* post entries, version 2*/

// vertical bar
#index-main.container {
    position: relative;
    box-sizing: border-box;

    &::before {
        content: '';
        position: absolute;
        height: 100%;
        width: 6px;
        background: #666; // #333 with opacity 0.75

        @media only screen and (max-width: $break-level-4) {
            content: none;
        }
    }
}

// template style for tags of post
.post-tags-template {
    display: inline-block;
    margin-left: .5rem;
    text-align: right;
    color: #666;
    opacity: .6;
    transition: opacity .3s ease-in-out;

    &:hover {
        opacity: 1;
    }

    &::before {
        content: "\f02c";
        font-family: FontAwesome;
    }

    a{
        text-decoration: none;
        outline: none;
        color: #666;
        margin: 0 .3rem;
        &:hover {
            color: #333;
            border-bottom: 2px solid #666;
        }

        transition: border .2s ease-in-out;
    }
}

$outer-circle-radius: 10px;
$inner-circle-radius: 8px;
$post-time-space: 1em;
.post-entry {
    font-size: 16px;
    line-height: 1.5;
    margin: 1.5em 0;
    padding: 0 1.5em;
    position: relative;
    display: flex;
    align-items: center;

    @media only screen and (max-width: $break-level-4) {
        flex-direction: column;
        padding: 0;
        margin: 3.5em 0;
        align-items: initial;

        &:first-child {
            margin-top: 0;
        }
    }

    .post-time {
        flex: none;
        font-family: $font-mono;
        font-size: 0.875rem;
        margin-right: 1rem;
        position: absolute;
        right: 100%;
        color: #CCC;
        transition: color .2s ease-in-out;
        white-space: nowrap; // chrome needs this
        top: 50%; // chrome will need this to center vertically

        @media only screen and (max-width: $break-level-4) {
            order: 1;
            margin: auto;
            bottom: .2ex;
            left: 0;
            right: auto;
            color: #666;
            opacity: .6;
            top: auto;
        }

        &::before {
            content: '';
            position: absolute;
            width: 20px;
            height: 20px;
            background: #666; // #333 with opacity 0.75
            border-radius: 100%;
            left: calc(100% + 1rem + #{$vertical-bar-width}/2 - #{$outer-circle-radius});
            top: calc(50% - #{$outer-circle-radius});

            @media only screen and (max-width: $break-level-4) {
                content: none;
                left: calc(-#{$post-time-space} - #{$outer-circle-radius});
            }

        }

        &::after {
            content: '';
            position: absolute;
            width: 16px;
            height: 16px;
            background: #FCF9E8;
            border-radius: 100%;
            transition: background-color .2s ease-in-out;
            left: calc(100% + 1rem + #{$vertical-bar-width}/2 - #{$inner-circle-radius});
            top: calc(50% - #{$inner-circle-radius});

            @media only screen and (max-width: $break-level-4) {
                content: none;
                left: calc(-#{$post-time-space} - #{$inner-circle-radius});
            }
        }
    }

    &:hover {
        .post-time{
            //border-bottom: 2px solid $color-underscore;
            color: #666;

            &::after {
                background: #A1EFE9;
            }
        }
    }

    .post-desc {
        flex: 1;
        //padding-left: calc(1rem + #{$vertical-bar-width});


        // style for post-title
        .post-title {
            border-bottom: 1px solid #EEE;
            transition: border-color .2s ease;
            font-weight: 600;
            font-size: 1.2em;

            &:hover {
                border-bottom: 1px solid #666;
            }

            a {
                color: #333;
                text-decoration: none;
                border: none;
                display: block;
                min-height: 1ex;
                outline: none;
            }
        }

        // style for post-meta
        .post-meta {
            text-align: right;
            min-height: 2em;
            display: flex;
            align-items: flex-end;
            flex-direction: row-reverse;
            justify-content: flex-start;
        }

        .post-tags {
            @extend .post-tags-template;
        }

        // style for post-categories
        .post-categories {
            @extend .post-tags-template;

            &::before {
                content: "\f07b";
            }
        }

        // hide tags when screen is too small
        @media only screen and (max-width: $break-level-2) {
            .post-tags {
                display: none;
            }
            .post-categories {
                margin: 0;
            }
        }

        // style for post description
        .post-content {
            padding-left: 2em;

            @media only screen and (max-width: $break-level-4) {
                padding-left: 0;
            }

            p {
                margin: 0.6em 0 0 0;
            }
        }
    }
}

/* paginator */

// make it occupy all width
.page-navigator-wrapper {
    @media only screen and (max-width: $break-level-3) {
        max-width: 100%;
    }
}
.page-navigator {
    margin: 3.5ex 0;
    overflow: hidden;
    text-align: center;
    border-bottom: 2px solid #CCC;
    color: #777;
    @media only screen and (max-width: $break-level-3) {
        border-top: 2px solid #CCC;
    }

    * {
        padding: 1px 20px;
    }

    .page-number {
        display: inline-block;
    }

    .current {
        color: #2F6EB6;
    }

    .prev {
        float: left;
    }

    .next {
        float: right;
    }


    a {
        color: inherit;
        text-decoration: none;
        &:hover {
            background: #BBB;
            color: #2F6EB6;
        }
    }
}


/**
 * footer
 */

footer#footer {
    text-align: right;
    margin-top: 2em;
    background: #333;

    &, & a, & a:visited {
        color: #AAA;
    }

    & a:hover {
        color: #EEE;
    }

    .bar {
        display: flex;
        //flex-wrap: wrap;

        .social {
            display: flex;
            align-items: center;
            //justify-content: center;
            a {
                display: inline-block;
                padding: 6px 12px;
                margin: 0 2px;
                font-size: 20px;

                transition: all .2s ease-in-out;

                &:hover {
                    background: #EEE;
                    color: #333;
                }
            }
        }

        .footer {
            flex: 1;
            padding: 1em 0;
        }

        @media only screen and (max-width: $break-level-3) {
            flex-direction: column;
            align-items: center;

            .social {
                padding: .5em .2em;
            }

            .footer {
                padding: .5em .2em;
                text-align: center
            }
        }
    }
}


/**
 * main content style
 */
.post-header h1 {
    font-family: $font-post-title;
    font-size: 2em;
}

/* post header meta data(time/tag) */
.wrapper .meta {
    //display: flex;
    //box-sizing: border-box;
    //padding: 0 20px;
    text-align: right;
    background: #333;
    color: #CCC;
    border-top: 2px solid #555;
    border-bottom: 2px solid #555;
    display: flex;
    box-shadow: 0 0 2px 1px rgba(200, 200, 200, 0.8);
    transition: background-color .2s ease-in-out;
    margin-bottom: 2em;

    // show full width on small screen
    @media only screen and (max-width: $break-level-2) {
        max-width: 100%;
    }

    &:hover {
        background: #222;
    }

    .post-time {
        flex: 1;
        text-align: left;
        font-family: $font-mono;
        font-size: 14px;
        align-self: center;
    }


    .post-tags, .post-categories {
        &::before {
            font-family: FontAwesome;
        }

        a {
            color: #CCC;
            text-decoration: none;
            margin: 0 .3rem;
            transition: border-bottom .3s ease-in-out, color .2s ease-in-out;

            &:hover {
                color: $color-underscore;
                border-bottom: 2px solid $color-underscore;
            }
        }
    }

    .post-tags {
        margin-left: 1em;
        &::before {
            content: "\f02c";
        }
    }

    .post-categories {
        &::before {
            content: "\f07b";
            font-family: FontAwesome;
        }
    }

    @media only screen and (max-width: $break-level-3) {
        flex-wrap: wrap;

        .post-tags, .post-categories {
            margin-left: auto;
        }
    }
}


article {
    /* global */
    font-size: 18px;
    line-height: 1.75;

    .entry {
        font-size: 16px;
    }


    /* headers */
    h1,h2,h3,h4,h5,h6 {
        font-family: $font-header;
        font-weight: 600;
    }

    h1 {
        border-bottom: 2px solid #333;
        padding: 3px 0;
        font-size: 2em;
    }

    h2 {
        border-bottom: 1px solid #CCC;
    }

    // rule
    hr {
        border-top: 3px dashed #878787;
        border-bottom: none;
    }

    // link
    a {
        color: $color-main-link;
        text-decoration: none;
        opacity: 0.9;

        transition: border .2s;
        transition: color .2s;
        border-bottom: .08em solid lightgray;
        &:hover {
            opacity: 1;
            border-bottom: .08em solid $color-main-link-hover;
            color: $color-main-link-hover;
        }
    }

    // ignore border-bottom for code blocks
    .post .highlight a {
        border: none !important;
    }

    // blockquote
    blockquote {
        margin: 1em 0;
        padding: 0 $article-padding;
        border-left: 5px solid $color-underscore;

        // block footer
        footer {
            font-size: 85%;
            cite::before {
                content: "—";
                padding: 0 0.5em;
                font-style: italic;
            }
        }
    }

    blockquote.pullquote.left {
        border: none;
        margin: 0 1em 0 .5em;
        width: 45%;
    }

    blockquote.pullquote.right {
        border: none;
        margin: 0 .5em 0 1em;
        width: 45%;
    }

    .left, .alignleft {
        float: left;
    }

    .right, .alignright {
        float: right;
    }

    // image
    img, video{
        display: block;
        height: auto;
        margin: auto;
        max-width: 100%;
        border: none;
        box-shadow: 0 0 5px 2px rgba(0, 0, 0, 0.4);
    }

    .video-container {
        position: relative;
        padding-top: 56.9%; // 16:9
        height: 0;
        overflow: hidden;
        iframe, object, embed {
            position: absolute;
            top: 0;
            left: 0;
            height: 100%;
            width: 100%;
            margin-top: 0;
        }
    }

    // cancel dangling list for the first level
    ol, ul {
        padding-left: 0;
        ol, ul {
            padding-left: 40px;
        }
    }

    // list
    li p {
        margin-top: 0;
        margin-bottom: 0;
    }

    // inline code
    code {
        border: 1px solid #BBB;
        background: #EEE;
        font-size: 14px;
    }

    // table
    table {
        width: 100%;
        border-collapse: collapse;
        border-spacing: 0;
        vertical-align: middle;

        th {
            text-align: left;
            background: #333;
            color: #EEE;
        }

        th, td {
            padding: 5px 8px;
            border: 1px solid #ddd;
        }

        tr:nth-child(2n) {
            background-color: #f2f2f2;
        }
    }
}

// fancybox
.article-gallery a.article-gallery-img {
    width: 100%;
    display: none;

    &:first-child {
        display: block;
    }

    img {
        width: 100%;
    }
}

// archive/category/tags page
.post-archive {
    // reset list indentation
    ol, ul {
        padding-left: 40px;
    }

    li .date {
        margin-right: 1em;
    }

    @media only screen and (max-width: $break-level-3-1) {
        ul {
            padding-left: 0;
            li {
                margin: 1em 0;
            }
        }
        a {
            display: block;
        }
    }
}

// category/tags on archive page
.list-unstyled {
    list-style: outside none none;
    padding-left: 0;
}

.all-categories, .all-tags {
    &::before {
        font-family: FontAwesome;
        float: left;
        margin-right: 1em;
    }

    ul.tag-box {
        display: flex;
        flex-wrap: wrap;

        li {
            a {
                display: inline;
                text-decoration: none;
                border: 1px dashed #CCC;
                border-radius: 3px;
                margin: .2em;
                padding: .1em .3em;
                outline: none;

                transition: none;

                span {
                    font-size: 0.8em;
                    border-left: 1px solid #CCC;
                    margin-left: .3em;
                    padding: 0 .3em;
                }

                &:hover {
                    background: #666;
                    color: #EEE;
                }
            }
        }
    }
}

.all-categories::before {
    content: "\f07b";
}

.all-tags::before {
    content: "\f02c";
}
